<template>
  <div class="lanjian-content">
    <div class="threeRow" >
      <a-form-model
        ref="ruleForm1"
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        :rules="rules"
        class='formbox cusFormBox'
        style="overflow: auto"
        :model="ruleForm"
      >
        <a-form-model-item class='formtabMax' label="巡察组评估情况">
          <a-textarea
            style="width: 100%;min-height: 100px"
            v-model:value='ruleForm.report_xcz_pg_infos'
            placeholder=""
            auto-size
            disabled="true"
            :rows="4"
          />
        </a-form-model-item>
        <a-form-model-item
          label='评估结果'
          class='formtab'
          prop='xcz_pz_yj'
        >
          <a-input
            v-model.trim='ruleForm.xcz_yj'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />

        </a-form-model-item>
        <a-form-model-item
          label='编辑人'
          class='formtab'
          prop='pzz_editor'
        >
          <a-input
            v-model.trim='ruleForm.report_xcz_editor'
            placeholder=''
            :maxLength=50
            disabled="true"
          />

        </a-form-model-item>
        <a-form-model-item
          label='联系电话'
          class='formtab cus'
          prop='pzz_phone'
        >
          <a-input
            v-model.trim='ruleForm.report_xcz_phone'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>

        <a-form-model-item label="组织部评估情况" class="formtabMax">
          <a-textarea
            style="width: 100%;min-height: 100px"
            v-model.trim:value="ruleForm.report_swzzb_pg_infos"
            placeholder=""

            disabled="true"
            autoSize
          />
        </a-form-model-item>
        <a-form-model-item
          label='评估结果'
          class='formtab'
        >
          <a-input
            v-model.trim='ruleForm.swzzb_yj'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />

        </a-form-model-item>
        <a-form-model-item
          label='编辑人'
          class='formtab'
          prop='jdjcs_editor'
        >
          <a-input
            v-model.trim='ruleForm.report_swzzb_editor'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>
        <a-form-model-item
          label='联系电话'
          class='formtab cus'
          prop='jdjcs_phone'
        >
          <a-input
            v-model.trim='ruleForm.report_swzzb_phone'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>

        <a-form-model-item label="派驻组评估情况" class="formtabMax">
          <a-textarea
            style="width: 100%;min-height: 100px"
            v-model.trim:value="ruleForm.report_pzz_pg_infos"
            placeholder=""

            disabled="true"
            autoSize
          />
        </a-form-model-item>
        <a-form-model-item
          label='评估结果'
          class='formtab'
          prop='xcz_pz_yj'
        >
          <a-input
            v-model.trim='ruleForm.pzz_yj'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />

        </a-form-model-item>
        <a-form-model-item
          label='编辑人'
          class='formtab'
          prop='jdjcs_editor'
        >
          <a-input
            v-model.trim='ruleForm.report_pzz_editor'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>
        <a-form-model-item
          label='联系电话'
          class='formtab cus'
          prop='jdjcs_phone'
        >
          <a-input
            v-model.trim='ruleForm.report_pzz_phone'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>

        <a-form-model-item label="监督检查室评估情况" class="formtabMax">
          <a-textarea
            style="width: 100%;min-height: 100px"
            v-model.trim:value="ruleForm.report_jdjcs_pg_infos"
            placeholder=""

            disabled="true"
            autoSize
          />
        </a-form-model-item>
        <a-form-model-item
          label='评估结果'
          class='formtab'
          prop='xcz_pz_yj'
        >
          <a-input
            v-model.trim='ruleForm.jdjcs_yj'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />

        </a-form-model-item>
        <a-form-model-item
          label='编辑人'
          class='formtab'
          prop='jdjcs_editor'
        >
          <a-input
            v-model.trim='ruleForm.report_jdjcs_editor'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>
        <a-form-model-item
          label='联系电话'
          class='formtab cus'
          prop='jdjcs_phone'
        >
          <a-input
            v-model.trim='ruleForm.report_jdjcs_phone'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>

        <a-form-model-item label="党风室汇总认定" class="formtabMax">
          <a-textarea
            style="width: 100%;min-height: 100px"
            v-model.trim:value="ruleForm.report_dfs_pg_infos"
            placeholder=""

            disabled="true"
            autoSize
          />
        </a-form-model-item>
        <a-form-model-item
          label='评估结果'
          class='formtab'
          prop='xcz_pz_yj'
        >
          <a-input
            v-model.trim='ruleForm.dfs_yj'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />

        </a-form-model-item>
        <a-form-model-item
          label='编辑人'
          class='formtab'
          prop='jdjcs_editor'
        >
          <a-input
            v-model.trim='ruleForm.report_dfs_editor'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>
        <a-form-model-item
          label='联系电话'
          class='formtab cus'
          prop='jdjcs_phone'
        >
          <a-input
            v-model.trim='ruleForm.report_dfs_phone'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>

        <a-form-model-item
          label='领导意见'
          class="formtabMax"
        >
          <a-textarea
            style="width: 100%;min-height: 100px"
            v-model:value='ruleForm.ldyj'
            placeholder=""
            auto-size
            disabled="true"
            :rows="4"
          />
        </a-form-model-item>
        <a-form-model-item
          label='附件'
          class="formtabMax"
        >
          <ui v-for="item in ruleForm.bgfj" :key="index" :value="item.value">
            <li><a @click="downtmp(item.tfpath,item.tfname)">{{ item.tfname }}</a></li>
          </ui>
        </a-form-model-item>
        <a-form-model-item
          label='id'
          class='formtab cus'
          v-show="false"
        >
          <a-input
            v-model.trim='ruleForm.id'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>
        <a-form-model-item
          label='id'
          class='formtab cus'
          v-show="false"
        >
          <a-input
            v-model.trim='ruleForm.f_status'
            placeholder=''
            :maxLength='200'
            disabled="true"
          />
        </a-form-model-item>
      </a-form-model>
    </div>
  </div>
</template>
<script>
import {
  getuploadFileInfo,
  addRectificationPlan,
  getRectificationPlanTotal,
  addRectificationReport, getRectificationReportTotal, addRectificationReportTotal, streamToBuffer,
} from '@/utils/JsonTools';
import UploadPlus from '@/components/UploadPlus/index.vue';
import { getLDType } from '@/utils/common';
import { getTemplete } from '@/utils/fileUtils';
import fs from 'fs';

export default {
  name: 'Total',
  components: { UploadPlus },
  data() {
    return {
      mulite: false,
      // 表单标题内容宽度设置
      labelCol: { span: 24 },
      wrapperCol: { span: 24 },
      ruleForm: { fileList: [] },
      // 表单规则
      rules: {
        fileList: [{ required: true, message: '请上传文件', trigger: ['blur', 'change'] }],
        phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
        editor: [{ required: true, message: '请输入编辑人', trigger: 'blur' }],
      },
      fileList: [],
    };
  },
  mounted() {
    this.getInfos();
  },
  methods: {
    // 上传验证
    beforeFileUpload(file) {
      if (file.name.substring(0, file.name.indexOf('.')).length > 200) {
        this.$message.error('上传文件名字不得超过200字');
        return false;
      }
      let isLt2M = file.size / 1024 / 1024;
      if (isLt2M > 200) {
        this.$message.error('只允许上传200M以下的文件');
        return false;
      }
      let fileExt = file.name.slice(file.name.lastIndexOf('.') + 1);
      let fileTypeArr = ['doc', 'docx', 'pdf', 'xls', 'xlsx', 'jpg', 'png', 'jpeg', 'txt', 'ext'];
      if (fileTypeArr.indexOf(fileExt) === -1) {
        this.$message.error('非法的文件类型');
        return false;
      }
      return true;
    },
    handleRemove() {
      this.ruleForm.fileList = [];
    },
    customUpload(file) {
      // beforeFileUpload()返回为true，才会触发这个方法；
      this.handleUpload(file);
    },
    // 构造formData
    handleUpload(file) {
      // const formData = new FormData()
      // let timestamp = new Date().getTime()
      // formData.append('files', file)
      // formData.append('fileUid', file.uid)
      // formData.append('totalBytes', file.size)
      // formData.append('time', timestamp)
      // this.imagerAdd(formData)
      getuploadFileInfo(file.file).then(res => {
        file.onSuccess(res);
        // eslint-disable-next-line no-unused-expressions
        this.ruleForm.fileList = [res];
        // this.ruleForm.fileList.push(res)
        //this.save()
      });
    },
    getInfos() {
      getRectificationReportTotal().then(res => {
        console.log('pp--', res);
        this.ruleForm = res;
        this.ruleForm.xcz_yj = getLDType(res.report_xcz_pg_yj);
        this.ruleForm.pzz_yj = getLDType(res.report_pzz_pg_yj);
        this.ruleForm.jdjcs_yj = getLDType(res.report_jdjcs_pg_yj);
        this.ruleForm.dfs_yj = getLDType(res.report_dfs_pg_yj);
        this.ruleForm.swzzb_yj = getLDType(res.report_swzzb_pg_yj);
        this.ruleForm.ld_yj = getLDType(res.ldyj);
      });
    },
    save() {
      this.$refs.ruleForm1.validate(valid => {
        // eslint-disable-next-line eqeqeq
        if (valid) {
          this.ruleForm.rep_status = 0;
          addRectificationReportTotal(this.ruleForm).then(res => {
            if (res === 0) {
              this.$message.error('保存失败');
              return;
            }
            this.$message.success('保存成功');
          });
        }
      });
    },
    downtmp(path, name) {
      let fileb = fs.createReadStream(path);
      let fsname = name;
      console.log('fsname-----' + fsname);
      streamToBuffer(fileb).then(res => {
        let data = res;
        let contents = new Uint8Array(data.length);
        for (let i = 0; i < data.length; i++) {
          contents[i] = data[i];
        }
        // eslint-disable-next-line no-undef
        let expname = fsname;
        saveAs.saveAs(new Blob([contents], { type: 'application/zip' }), expname);
      });
    },
  },
};
</script>
<style scoped lang="less">
/deep/ .formbox{
  height: calc(100vh - 264px);
}
/deep/ .ant-form-item-label {
  width: 176px;
}

/deep/ .ant-input {
  width: 260px
}
</style>
<style lang="scss">
// 滚动条背景颜色
.ant-form::-webkit-scrollbar,
.info::-webkit-scrollbar {
  height: 9px;
  width: 9px;
  background-color: #fcfcfc;
}

// 滚动条颜色
.ant-form::-webkit-scrollbar-thumb,
.info::-webkit-scrollbar-thumb {
  border-radius: 9px;
  background-color: #cccccc;
}

.ant-form-item label {
  font-weight: bold;
}

</style>
<style lang="scss">
// 滚动条背景颜色
.lanjian-content::-webkit-scrollbar,
.info::-webkit-scrollbar {
  height: 9px;
  width: 9px;
  background-color: #fcfcfc;
}

// 滚动条颜色
.lanjian-content::-webkit-scrollbar-thumb,
.info::-webkit-scrollbar-thumb {
  border-radius: 9px;
  background-color: #cccccc;
}

</style>
